//
//  GYCompany.m
//  LockManagement
//
//  Created by 丁燕春 on 2018/8/3.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYCompany.h"
#import "GYNetWorkTools.h"

@implementation GYCompany

+ (void)getComapngList:(void (^)(NSArray *))success error:(void (^)(NSError *))failed {
    NSMutableArray *companyLists = [NSMutableArray array];
    [GYNetWorkTools requestGetCompanyListWithURL:@"http://120.79.103.234:7070/api/getCompanyList" current:@"" pageSize:@"" success:^(NSDictionary *obj) {
        //NSLog(@"companyList=======%@",obj);
        int state = [[obj objectForKey:@"state"] intValue];
        if (state == 0) {
            NSArray *data = [obj objectForKey:@"data"];
            for (NSDictionary *tempDic in data) {
                GYCompany *company = [[GYCompany alloc] initWithDic:tempDic];
                [companyLists addObject:company];
            }
            
            success(companyLists);
        }
    } error:^(NSError *error) {
        failed(error);
        [SVProgressHUD showErrorWithStatus:@"您的网络不太通常..."];
        NSLog(@"loadCompanyList error =======%@",error);
    }];
}

- (instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dic];
    }
    
    return self;
}

- (instancetype)initWith:(NSString *)companyName companyID:(NSString *)companyID {
    self = [super init];
    if (self) {
        _companyName = companyName;
        _companyID = companyID;
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key  {
    
}

- (NSString *)description {
    NSArray *keys = @[@"companyID",@"companyName"];
    return [NSString stringWithFormat:@"%@",[self dictionaryWithValuesForKeys:keys]];
}

@end
